package org.springblade.modules.notice.core.event;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.notice.core.Process;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import javax.annotation.Resource;

/**
 * @Author ysq
 * @Date 2024/12/11
 * @Description 消息事件监听
 */
@Slf4j
@Component
public class NoticeListener {

	@Resource
	private Process process;

	@Async("noticeTaskExecutor")
	@TransactionalEventListener(classes = NoticeEvent.class, phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
	public void onNoticeEvent(NoticeEvent noticeEvent) {
		log.info("消息事件监听：{}", JSONUtil.toJsonStr(noticeEvent.getNoticeTaskParam()));
		process.noticeBusinessProcess(noticeEvent.getNoticeTaskParam());
	}
}
